package com.ouc.eddyAlgorithm.service.impl;

import com.ouc.common.core.text.Convert;
import com.ouc.eddyAlgorithm.domain.VgForecast;
import com.ouc.eddyAlgorithm.mapper.VgForecastMapper;
import com.ouc.eddyAlgorithm.service.IVgForecastService;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * vg涡旋预测Service业务层处理
 *
 * @author b504
 * @date 2023-03-09
 */
@Service
public class VgForecastServiceImpl implements IVgForecastService {
  @Autowired
  private VgForecastMapper vgForecastMapper;

  @Autowired
  private SqlSessionFactory sqlSessionFactory;

  /**
   * 查询vg涡旋预测
   *
   * @param id vg涡旋预测主键
   * @return vg涡旋预测
   */
  @Override
  public VgForecast selectVgForecastById(Integer id) {
    return vgForecastMapper.selectVgForecastById(id);
  }

  /**
   * 查询vg涡旋预测列表
   *
   * @param vgForecast vg涡旋预测
   * @return vg涡旋预测
   */
  @Override
  public List<VgForecast> selectVgForecastList(VgForecast vgForecast) {
    return vgForecastMapper.selectVgForecastList(vgForecast);
  }

  /**
   * 新增vg涡旋预测
   *
   * @param vgForecast vg涡旋预测
   * @return 结果
   */
  @Override
  public int insertVgForecast(VgForecast vgForecast) {
    return vgForecastMapper.insertVgForecast(vgForecast);
  }

  /**
   * 修改vg涡旋预测
   *
   * @param vgForecast vg涡旋预测
   * @return 结果
   */
  @Override
  public int updateVgForecast(VgForecast vgForecast) {
    return vgForecastMapper.updateVgForecast(vgForecast);
  }

  /**
   * 批量删除vg涡旋预测
   *
   * @param ids 需要删除的vg涡旋预测主键
   * @return 结果
   */
  @Override
  public int deleteVgForecastByIds(String ids) {
    return vgForecastMapper.deleteVgForecastByIds(Convert.toStrArray(ids));
  }

  /**
   * 删除vg涡旋预测信息
   *
   * @param id vg涡旋预测主键
   * @return 结果
   */
  @Override
  public int deleteVgForecastById(Integer id) {
    return vgForecastMapper.deleteVgForecastById(id);
  }

  @Override
  public void insertByBatch(List<VgForecast> vgForecastList) {
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
    VgForecastMapper mapper = sqlSession.getMapper(VgForecastMapper.class);
    for (VgForecast vgForecast : vgForecastList) {
      mapper.insertVgForecast(vgForecast);
    }
    sqlSession.commit();
    sqlSession.clearCache();
    sqlSession.close();

  }

}
